home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / vibrant / vibextra.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-17  |  22.3 KB  |  889 lines  |  [TEXT/R*ch]

  1. /*   vibextra.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibextra.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   3/9/93
  31. *
  32. * $Revision: 1.15 $
  33. *
  34. * File Description: 
  35. *       Vibrant miscellaneous extensions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49. #include <ncbiport.h>
  50.  
  51. #ifdef VAR_ARGS
  52. #include <varargs.h>
  53. #else
  54. #include <stdarg.h>
  55. #endif
  56.  
  57. typedef  struct  Nlm_repeatdata {
  58.   Nlm_Handle       title;
  59.   Nlm_RptClckProc  action;
  60. } Nlm_RepeatData;
  61.  
  62. typedef struct Nlm_switchdata {
  63.   Nlm_Int2         max;
  64.   Nlm_Int2         val;
  65.   Nlm_Boolean      text;
  66.   Nlm_Boolean      vert;
  67.   Nlm_Boolean      upActv;
  68.   Nlm_Boolean      dnActv;
  69.   Nlm_SwtChngProc  actn;
  70. } Nlm_SwitchData;
  71.  
  72. typedef  struct  Nlm_icondata {
  73.   Nlm_IcnChngProc  inval;
  74.   Nlm_Int2         value;
  75.   Nlm_Boolean      status;
  76.   Nlm_Handle       title;
  77. } Nlm_IconData;
  78.  
  79. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  80.  
  81. static Nlm_GphPrcsPtr  repeatProcs;
  82. static Nlm_GphPrcsPtr  switchProcs;
  83. static Nlm_GphPrcsPtr  iconProcs;
  84.  
  85. static Nlm_Boolean     inRepeatButton;
  86.  
  87. static Nlm_Uint1 upFillArrow [] = {
  88.   0x10, 0x38, 0x38, 0x7C, 0x7C, 0xFE, 0xFE, 0x00
  89. };
  90.  
  91. static Nlm_Uint1 downFillArrow [] = {
  92.   0xFE, 0xFE, 0x7C, 0x7C, 0x38, 0x38, 0x10, 0x00
  93. };
  94.  
  95. static Nlm_Uint1 leftFillArrow [] = {
  96.   0x06, 0x1E, 0x7E, 0xFE, 0x7E, 0x1E, 0x06, 0x00
  97. };
  98.  
  99. static Nlm_Uint1 rightFillArrow [] = {
  100.   0xC0, 0xF0, 0xFC, 0xFE, 0xFC, 0xF0, 0xC0, 0x00
  101. };
  102.  
  103. static Nlm_Uint1 upOpenArrow [] = {
  104.   0x10, 0x28, 0x28, 0x44, 0x44, 0x82, 0xFE, 0x00
  105. };
  106.  
  107. static Nlm_Uint1 downOpenArrow [] = {
  108.   0xFE, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x00
  109. };
  110.  
  111. static Nlm_Uint1 leftOpenArrow [] = {
  112.   0x06, 0x1A, 0x62, 0x82, 0x62, 0x1A, 0x06, 0x00
  113. };
  114.  
  115. static Nlm_Uint1 rightOpenArrow [] = {
  116.   0xC0, 0xB0, 0x8C, 0x82, 0x8C, 0xB0, 0xC0, 0x00
  117. };
  118.  
  119. #ifdef VAR_ARGS
  120. extern void CDECL Nlm_AlignObjects (align, va_alist)
  121. int align;
  122. va_dcl
  123. #else
  124. extern void CDECL Nlm_AlignObjects (int align, ...)
  125. #endif
  126.  
  127. {
  128.   va_list     args;
  129.   Nlm_Int2    delta;
  130.   Nlm_Int2    maxX;
  131.   Nlm_Int2    maxY;
  132.   Nlm_Int2    minX;
  133.   Nlm_Int2    minY;
  134.   Nlm_Handle  obj;
  135.   Nlm_RecT    r;
  136.  
  137. #ifdef VAR_ARGS
  138.   va_start (args);
  139. #else
  140.   va_start (args, align);
  141. #endif
  142.   minX = 0;
  143.   minY = 0;
  144.   maxX = 0;
  145.   maxY = 0;
  146.   obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  147.   while (obj != NULL) {
  148.     Nlm_GetPosition (obj, &r);
  149.     minX = MAX (minX, r.left);
  150.     minY = MAX (minY, r.top);
  151.     maxX = MAX (maxX, r.right);
  152.     maxY = MAX (maxY, r.bottom);
  153.     obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  154.   }
  155.   va_end(args);
  156.  
  157. #ifdef VAR_ARGS
  158.   va_start (args);
  159. #else
  160.   va_start (args, align);
  161. #endif
  162.   obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  163.   while (obj != NULL) {
  164.     Nlm_GetPosition (obj, &r);
  165.     switch (align) {
  166.       case ALIGN_LEFT:
  167.         if (r.left < minX) {
  168.           r.left = minX;
  169.           Nlm_SetPosition (obj, &r);
  170.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  171.         }
  172.         break;
  173.       case ALIGN_RIGHT:
  174.         if (r.right < maxX) {
  175.           r.right = maxX;
  176.           Nlm_SetPosition (obj, &r);
  177.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  178.         }
  179.         break;
  180.       case ALIGN_CENTER:
  181.         delta = maxX - r.right;
  182.         if (delta > 0) {
  183.           Nlm_OffsetRect (&r, delta/2, 0);
  184.           Nlm_SetPosition (obj, &r);
  185.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  186.         }
  187.         break;
  188.       case ALIGN_JUSTIFY:
  189.         if (r.left < minX || r.right < maxX) {
  190.           r.left = minX;
  191.           r.right = maxX;
  192.           Nlm_SetPosition (obj, &r);
  193.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  194.         }
  195.         break;
  196.       case ALIGN_UPPER:
  197.         if (r.top < minY) {
  198.           r.top = minY;
  199.           Nlm_SetPosition (obj, &r);
  200.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  201.         }
  202.         break;
  203.       case ALIGN_LOWER:
  204.         if (r.bottom < maxY) {
  205.           r.bottom = maxY;
  206.           Nlm_SetPosition (obj, &r);
  207.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  208.         }
  209.         break;
  210.       case ALIGN_MIDDLE:
  211.         delta = maxY - r.bottom;
  212.         if (delta > 0) {
  213.           Nlm_OffsetRect (&r, 0, delta/2);
  214.           Nlm_SetPosition (obj, &r);
  215.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  216.         }
  217.         break;
  218.       case ALIGN_VERTICAL:
  219.         if (r.top < minY || r.bottom < maxY) {
  220.           r.top = minY;
  221.           r.bottom = maxY;
  222.           Nlm_SetPosition (obj, &r);
  223.           Nlm_DoAdjustPrnt ((Nlm_GraphiC) obj, &r, FALSE, TRUE);
  224.         }
  225.         break;
  226.       default:
  227.         break;
  228.     }
  229.     obj = (Nlm_Handle) va_arg (args, Nlm_HANDLE);
  230.   }
  231.   va_end(args);
  232. }
  233.  
  234. static void Nlm_DrawSwitchProc (Nlm_PaneL s)
  235.  
  236. {
  237.   Nlm_RecT        dn;
  238.   Nlm_SwitchData  extra;
  239.   Nlm_Int2        mid;
  240.   Nlm_RecT        r;
  241.   Nlm_Char        str [32];
  242.   Nlm_RecT        tx;
  243.   Nlm_RecT        up;
  244.  
  245.   Nlm_GetPanelExtra (s, &extra);
  246.   Nlm_ObjectRect (s, &r);
  247.   if (extra.text && extra.max > 0 && extra.val > 0) {
  248.     sprintf (str, "%d/%d", (int) extra.val, (int) extra.max);
  249.     Nlm_SelectFont (Nlm_programFont);
  250.     if (extra.vert) {
  251.       Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 11, r.bottom - 1);
  252.     } else {
  253.       Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 20, r.bottom - 1);
  254.     }
  255.     Nlm_DrawString (&tx, str, 'r', FALSE);
  256.     Nlm_SelectFont (Nlm_systemFont);
  257.   }
  258.   Nlm_FrameRect (&r);
  259.   if (extra.vert) {
  260.     Nlm_LoadRect (&up, r.right - 9, r.top + 2, r.right - 2, r.top + 9);
  261.     if (extra.upActv) {
  262.       Nlm_CopyBits (&up, upFillArrow);
  263.     } else {
  264.       Nlm_CopyBits (&up, upOpenArrow);
  265.     }
  266.   } else {
  267.     mid = (r.top + r.bottom) / 2;
  268.     Nlm_LoadRect (&up, r.right - 9, mid - 3, r.right - 2, mid + 4);
  269.     if (extra.upActv) {
  270.       Nlm_CopyBits (&up, rightFillArrow);
  271.     } else {
  272.       Nlm_CopyBits (&up, rightOpenArrow);
  273.     }
  274.   }
  275.   if (extra.vert) {
  276.     Nlm_LoadRect (&dn, r.right - 9, r.bottom - 9, r.right - 2, r.bottom - 2);
  277.     if (extra.dnActv) {
  278.       Nlm_CopyBits (&dn, downFillArrow);
  279.     } else {
  280.       Nlm_CopyBits (&dn, downOpenArrow);
  281.     }
  282.   } else {
  283.     mid = (r.top + r.bottom) / 2;
  284.     Nlm_LoadRect (&dn, r.right - 18, mid - 3, r.right - 11, mid + 4);
  285.     if (extra.dnActv) {
  286.       Nlm_CopyBits (&dn, leftFillArrow);
  287.     } else {
  288.       Nlm_CopyBits (&dn, leftOpenArrow);
  289.     }
  290.   }
  291. }
  292.  
  293. static void Nlm_SwitchClickProc (Nlm_PaneL s, Nlm_PoinT pt)
  294.  
  295. {
  296.   Nlm_RecT        dn;
  297.   Nlm_SwitchData  extra;
  298.   Nlm_Int2        mid;
  299.   Nlm_RecT        r;
  300.   Nlm_RecT        up;
  301.  
  302.   Nlm_GetPanelExtra (s, &extra);
  303.   Nlm_ObjectRect (s, &r);
  304.   if (extra.vert) {
  305.     Nlm_LoadRect (&up, r.right - 9, r.top + 2, r.right - 2, r.top + 9);
  306.     Nlm_LoadRect (&dn, r.right - 9, r.bottom - 9, r.right - 2, r.bottom - 2);
  307.   } else {
  308.     mid = (r.top + r.bottom) / 2;
  309.     Nlm_LoadRect (&up, r.right - 9, mid - 3, r.right - 2, mid + 4);
  310.     Nlm_LoadRect (&dn, r.right - 18, mid - 3, r.right - 11, mid + 4);
  311.   }
  312.   if (Nlm_PtInRect (pt, &up)) {
  313.     if (extra.val < extra.max) {
  314.       Nlm_DoSetValue ((Nlm_GraphiC) s, extra.val + 1, FALSE);
  315.       if (extra.actn != NULL) {
  316.         extra.actn ((Nlm_SwitcH) s, extra.val + 1, extra.val);
  317.       }
  318.     }
  319.   } else if (Nlm_PtInRect (pt, &dn)) {
  320.     if (extra.val > 1) {
  321.       Nlm_DoSetValue ((Nlm_GraphiC) s, extra.val - 1, FALSE);
  322.       if (extra.actn != NULL) {
  323.         extra.actn ((Nlm_SwitcH) s, extra.val - 1, extra.val);
  324.       }
  325.     }
  326.   }
  327. }
  328.  
  329. static Nlm_SwitcH Nlm_CommonSwitch (Nlm_GrouP prnt, Nlm_Boolean text,
  330.                                     Nlm_Boolean vert, Nlm_SwtChngProc actn)
  331.  
  332. {
  333.   Nlm_SwitchData  extra;
  334.   Nlm_Int2        height;
  335.   Nlm_PaneL       s;
  336.   Nlm_Int2        width;
  337.  
  338.   s = NULL;
  339.   if (prnt != NULL) {
  340.     Nlm_SelectFont (Nlm_programFont);
  341.     if (vert) {
  342.       height = 20;
  343.       width = 11;
  344.     } else {
  345.       height = 11;
  346.       width = 20;
  347.     }
  348.     if (text) {
  349.       width += Nlm_StringWidth ("99/99") + 4;
  350.       height = MAX (height, Nlm_LineHeight () + 2);
  351.     }
  352.     Nlm_SelectFont (Nlm_systemFont);
  353.     s = Nlm_AutonomousPanel (prnt, width, height, Nlm_DrawSwitchProc, NULL,
  354.                              NULL, sizeof (Nlm_SwitchData), NULL, switchProcs);
  355.     if (s != NULL) {
  356.       Nlm_SetPanelClick (s, Nlm_SwitchClickProc, NULL, NULL, NULL);
  357.       Nlm_MemSet ((Nlm_VoidPtr) (&extra), 0, sizeof (Nlm_SwitchData));
  358.       extra.max = 0;
  359.       extra.val = 0;
  360.       extra.text = text;
  361.       extra.vert = vert;
  362.       extra.upActv = FALSE;
  363.       extra.dnActv = FALSE;
  364.       extra.actn = actn;
  365.       Nlm_SetPanelExtra (s, &extra);
  366.     }
  367.   }
  368.   return (Nlm_SwitcH) s;
  369. }
  370.  
  371. extern Nlm_SwitcH Nlm_UpDownSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
  372.  
  373. {
  374.   return Nlm_CommonSwitch (prnt, text, TRUE, actn);
  375. }
  376.  
  377. extern Nlm_SwitcH Nlm_LeftRightSwitch (Nlm_GrouP prnt, Nlm_Boolean text, Nlm_SwtChngProc actn)
  378.  
  379. {
  380.   return Nlm_CommonSwitch (prnt, text, FALSE, actn);
  381. }
  382.  
  383. static void Nlm_UpdateSwitch (Nlm_SwitcH s)
  384.  
  385. {
  386.   Nlm_RecT        dn;
  387.   Nlm_SwitchData  extra;
  388.   Nlm_Int2        mid;
  389.   Nlm_RecT        r;
  390.   Nlm_RecT        tx;
  391.   Nlm_RecT        up;
  392.  
  393.   Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  394.   if (Nlm_Visible (s) && Nlm_AllParentsVisible (s)) {
  395.     Nlm_ObjectRect (s, &r);
  396.     if (extra.vert) {
  397.       Nlm_LoadRect (&up, r.right - 9, r.top + 2, r.right - 2, r.top + 9);
  398.       Nlm_LoadRect (&dn, r.right - 9, r.bottom - 9, r.right - 2, r.bottom - 2);
  399.     } else {
  400.       mid = (r.top + r.bottom) / 2;
  401.       Nlm_LoadRect (&up, r.right - 9, mid - 3, r.right - 2, mid + 4);
  402.       Nlm_LoadRect (&dn, r.right - 18, mid - 3, r.right - 11, mid + 4);
  403.     }
  404.     Nlm_Select (s);
  405.     if (extra.upActv != (Nlm_Boolean) (extra.val < extra.max)) {
  406.       Nlm_InsetRect (&up, -1, -1);
  407.       Nlm_InvalRect (&up);
  408.     }
  409.     if (extra.dnActv != (Nlm_Boolean) (extra.val > 1)) {
  410.       Nlm_InsetRect (&dn, -1, -1);
  411.       Nlm_InvalRect (&dn);
  412.     }
  413.     if (extra.text) {
  414.       if (extra.vert) {
  415.         Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 10, r.bottom - 1);
  416.       } else {
  417.         Nlm_LoadRect (&tx, r.left + 1, r.top + 1, r.right - 19, r.bottom - 1);
  418.       }
  419.       Nlm_InvalRect (&tx);
  420.     }
  421.   }
  422.   extra.upActv = (Nlm_Boolean) (extra.val < extra.max);
  423.   extra.dnActv = (Nlm_Boolean) (extra.val > 1);
  424.   Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  425. }
  426.  
  427. static void Nlm_SetSwitchValue (Nlm_GraphiC s, Nlm_Int2 value, Nlm_Boolean savePort)
  428.  
  429. {
  430.   Nlm_SwitchData  extra;
  431.   Nlm_Int2        oldval;
  432.   Nlm_WindoW      tempPort;
  433.  
  434.   tempPort = Nlm_SavePortIfNeeded (s, savePort);
  435.   if (s != NULL) {
  436.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  437.     oldval = extra.val;
  438.     extra.val = value;
  439.     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  440.     if (oldval != value) {
  441.       Nlm_UpdateSwitch ((Nlm_SwitcH) s);
  442.     }
  443.   }
  444.   Nlm_RestorePort (tempPort);
  445. }
  446.  
  447. static Nlm_Int2 Nlm_GetSwitchValue (Nlm_GraphiC s)
  448.  
  449. {
  450.   Nlm_SwitchData  extra;
  451.   Nlm_Int2        value;
  452.  
  453.   value = 0;
  454.   if (s != NULL) {
  455.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  456.     value = extra.val;
  457.   }
  458.   return value;
  459. }
  460.  
  461. extern void Nlm_SetSwitchMax (Nlm_SwitcH s, Nlm_Int2 max)
  462.  
  463. {
  464.   Nlm_SwitchData  extra;
  465.   Nlm_Int2        oldmax;
  466.   Nlm_WindoW      tempPort;
  467.  
  468.   tempPort = Nlm_SavePort (s);
  469.   if (s != NULL) {
  470.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  471.     oldmax = extra.max;
  472.     extra.max = max;
  473.     if (max == 0) {
  474.       extra.val = 0;
  475.     }
  476.     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  477.     if (oldmax != max) {
  478.       Nlm_UpdateSwitch (s);
  479.     }
  480.   }
  481.   Nlm_RestorePort (tempPort);
  482. }
  483.  
  484. extern Nlm_Int2 Nlm_GetSwitchMax (Nlm_SwitcH s)
  485.  
  486. {
  487.   Nlm_SwitchData  extra;
  488.   Nlm_Int2        max;
  489.  
  490.   max = 0;
  491.   if (s != NULL) {
  492.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  493.     max = extra.max;
  494.   }
  495.   return max;
  496. }
  497.  
  498. extern void Nlm_SetSwitchParams (Nlm_SwitcH s, Nlm_Int2 value, Nlm_Int2 max)
  499.  
  500. {
  501.   Nlm_SwitchData  extra;
  502.   Nlm_Int2        oldmax;
  503.   Nlm_Int2        oldval;
  504.   Nlm_WindoW      tempPort;
  505.  
  506.   tempPort = Nlm_SavePort (s);
  507.   if (s != NULL) {
  508.     Nlm_GetPanelExtra ((Nlm_PaneL) s, &extra);
  509.     oldmax = extra.max;
  510.     extra.max = max;
  511.     if (value > max) {
  512.       value = max;
  513.     }
  514.     oldval = extra.val;
  515.     extra.val = value;
  516.     Nlm_SetPanelExtra ((Nlm_PaneL) s, &extra);
  517.     if (oldval != value || oldmax != max) {
  518.       Nlm_UpdateSwitch (s);
  519.     }
  520.   }
  521.   Nlm_RestorePort (tempPort);
  522. }
  523.  
  524. static void Nlm_DoRepeatAction (Nlm_RepeaT rb, Nlm_PoinT pt)
  525.  
  526. {
  527.   Nlm_RptClckProc  actn;
  528.   Nlm_RepeatData   rdata;
  529.  
  530.   Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
  531.   actn = rdata.action;
  532.   if (actn != NULL) {
  533.     actn (rb, pt);
  534.   }
  535. }
  536.  
  537. static void Nlm_RepeatClick (Nlm_PaneL rb, Nlm_PoinT pt)
  538.  
  539. {
  540.   Nlm_RecT  r;
  541.  
  542.   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  543.   if (Nlm_PtInRect (pt, &r)) {
  544.     inRepeatButton = TRUE;
  545.     Nlm_InsetRect (&r, 2, 2);
  546.     Nlm_InvertRect (&r);
  547.     Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
  548.   }
  549. }
  550.  
  551. static void Nlm_RepeatPress (Nlm_PaneL rb, Nlm_PoinT pt)
  552.  
  553. {
  554.   Nlm_RecT  r;
  555.  
  556.   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  557.   if (Nlm_PtInRect (pt, &r)) {
  558.     if (! inRepeatButton) {
  559.       inRepeatButton = TRUE;
  560.       Nlm_InsetRect (&r, 2, 2);
  561.       Nlm_InvertRect (&r);
  562.     }
  563.     Nlm_DoRepeatAction ((Nlm_RepeaT) rb, pt);
  564.   } else if (inRepeatButton) {
  565.     inRepeatButton = FALSE;
  566.     Nlm_InsetRect (&r, 2, 2);
  567.     Nlm_InvertRect (&r);
  568.   }
  569. }
  570.  
  571. static void Nlm_RepeatRelease (Nlm_PaneL rb, Nlm_PoinT pt)
  572.  
  573. {
  574.   Nlm_RecT  r;
  575.  
  576.   Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  577.   if (inRepeatButton) {
  578.     inRepeatButton = FALSE;
  579.     Nlm_InsetRect (&r, 2, 2);
  580.     Nlm_InvertRect (&r);
  581.   }
  582. }
  583.  
  584. static void Nlm_DrawRepeat (Nlm_PaneL rb)
  585.  
  586. {
  587.   Nlm_Handle      h;
  588.   Nlm_RecT        r;
  589.   Nlm_RepeatData  rdata;
  590.   Nlm_Char        str [64];
  591.  
  592.   if (Nlm_GetVisible ((Nlm_GraphiC) rb) && Nlm_GetAllParentsVisible ((Nlm_GraphiC) rb)) {
  593.     Nlm_GetRect ((Nlm_GraphiC) rb, &r);
  594.     Nlm_FrameRect (&r);
  595.     Nlm_InsetRect (&r, 1, 1);
  596.     Nlm_FrameRect (&r);
  597.     Nlm_InsetRect (&r, 1, 1);
  598.     Nlm_GetPanelExtra (rb, &rdata);
  599.     h = rdata.title;
  600.     if (h != NULL) {
  601.       Nlm_SelectFont (Nlm_systemFont);
  602.       Nlm_GetString (h, str, sizeof (str));
  603.       if (Nlm_StringLen (str) > 0) {
  604.         Nlm_DrawString (&r, str, 'c', FALSE);
  605.       }
  606.     }
  607.   }
  608. }
  609.  
  610. static void Nlm_SetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
  611.                                 Nlm_CharPtr title, Nlm_Boolean savePort)
  612.  
  613. {
  614.   Nlm_Handle      h;
  615.   Nlm_RecT        r;
  616.   Nlm_RepeatData  rdata;
  617.   Nlm_WindoW      tempPort;
  618.  
  619.   tempPort = Nlm_SavePortIfNeeded (rb, savePort);
  620.   Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
  621.   h = rdata.title;
  622.   h = Nlm_SetString (h, title);
  623.   rdata.title = h;
  624.   Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
  625.   if (Nlm_GetVisible (rb) && Nlm_GetAllParentsVisible (rb)) {
  626.     Nlm_GetRect (rb, &r);
  627.     Nlm_InvalRect (&r);
  628.   }
  629.   Nlm_RestorePort (tempPort);
  630. }
  631.  
  632. static void Nlm_GetRepeatTitle (Nlm_GraphiC rb, Nlm_Int2 item,
  633.                                 Nlm_CharPtr title, Nlm_sizeT maxsize)
  634.  
  635. {
  636.   Nlm_Handle      h;
  637.   Nlm_RepeatData  rdata;
  638.  
  639.   if (title != NULL) {
  640.     Nlm_GetPanelExtra ((Nlm_PaneL) rb, &rdata);
  641.     h = rdata.title;
  642.     Nlm_GetString (h, title, maxsize);
  643.   }
  644. }
  645.  
  646. static void Nlm_ResetRepeat (Nlm_PaneL rb)
  647.  
  648. {
  649.   Nlm_RepeatData  rdata;
  650.  
  651.   Nlm_GetPanelExtra (rb, &rdata);
  652.   if (rdata.title != NULL) {
  653.     rdata.title = Nlm_HandFree (rdata.title);
  654.   }
  655.   Nlm_SetPanelExtra (rb, &rdata);
  656. }
  657.  
  658. extern Nlm_RepeaT Nlm_RepeatButton (Nlm_GrouP prnt, Nlm_CharPtr title,
  659.                                     Nlm_RptClckProc actn)
  660.  
  661. {
  662.   Nlm_RepeaT      rb;
  663.   Nlm_RepeatData  rdata;
  664.   Nlm_Int2        vbounds;
  665.   Nlm_Int2        width;
  666.  
  667.   rb = NULL;
  668.   if (prnt != NULL) {
  669.     Nlm_SelectFont (Nlm_systemFont);
  670.     width = Nlm_StringWidth (title);
  671. #ifdef WIN_MAC
  672.     vbounds = 2;
  673. #endif
  674. #ifdef WIN_MSWIN
  675.     vbounds = 4;
  676. #endif
  677. #ifdef WIN_MOTIF
  678.     vbounds = 2;
  679. #endif
  680.     rb = (Nlm_RepeaT) Nlm_AutonomousPanel (prnt, width+8, Nlm_stdLineHeight+vbounds*2,
  681.                                            Nlm_DrawRepeat, NULL, NULL,
  682.                                            sizeof (Nlm_RepeatData), Nlm_ResetRepeat,
  683.                                            repeatProcs);
  684.     if (rb != NULL) {
  685.       Nlm_SetPanelClick ((Nlm_PaneL) rb, Nlm_RepeatClick, NULL,
  686.                          Nlm_RepeatPress, Nlm_RepeatRelease);
  687.       rdata.title = NULL;
  688.       rdata.action = actn;
  689.       Nlm_SetPanelExtra ((Nlm_PaneL) rb, &rdata);
  690.       Nlm_SetRepeatTitle ((Nlm_GraphiC) rb, 0, title, FALSE);
  691.     }
  692.   }
  693.   return rb;
  694. }
  695.  
  696. static void Nlm_SetIconValue (Nlm_GraphiC i, Nlm_Int2 value, Nlm_Boolean savePort)
  697.  
  698. {
  699.   Nlm_IconData  extra;
  700.   Nlm_Int2      oldval;
  701.   Nlm_RecT      r;
  702.   Nlm_WindoW    tempPort;
  703.  
  704.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  705.   if (i != NULL) {
  706.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  707.     oldval = extra.value;
  708.     extra.value = value;
  709.     Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
  710.     if (oldval != value) {
  711.       if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
  712.         Nlm_Select (i);
  713.         if (extra.inval != NULL) {
  714.           extra.inval ((Nlm_IcoN) i, value, oldval);
  715.         } else {
  716.           Nlm_ObjectRect (i, &r);
  717.           Nlm_InsetRect (&r, -1, -1);
  718.           Nlm_InvalRect (&r);
  719.         }
  720.       }
  721.     }
  722.   }
  723.   Nlm_RestorePort (tempPort);
  724. }
  725.  
  726. static Nlm_Int2 Nlm_GetIconValue (Nlm_GraphiC i)
  727.  
  728. {
  729.   Nlm_IconData  extra;
  730.   Nlm_Int2      value;
  731.  
  732.   value = 0;
  733.   if (i != NULL) {
  734.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  735.     value = extra.value;
  736.   }
  737.   return value;
  738. }
  739.  
  740. static void Nlm_SetIconStatus (Nlm_GraphiC i, Nlm_Int2 item,
  741.                                Nlm_Boolean set, Nlm_Boolean savePort)
  742.  
  743. {
  744.   Nlm_IconData  extra;
  745.   Nlm_Boolean   oldstat;
  746.   Nlm_RecT      r;
  747.   Nlm_WindoW    tempPort;
  748.  
  749.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  750.   if (i != NULL) {
  751.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  752.     oldstat = extra.status;
  753.     extra.status = set;
  754.     Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
  755.     if (oldstat != set) {
  756.       if (Nlm_Visible (i) && Nlm_AllParentsVisible (i)) {
  757.         Nlm_Select (i);
  758.         if (extra.inval != NULL) {
  759.           extra.inval ((Nlm_IcoN) i, extra.value, extra.value);
  760.         } else {
  761.           Nlm_ObjectRect (i, &r);
  762.           Nlm_InsetRect (&r, -1, -1);
  763.           Nlm_InvalRect (&r);
  764.         }
  765.       }
  766.     }
  767.   }
  768.   Nlm_RestorePort (tempPort);
  769. }
  770.  
  771. static Nlm_Boolean Nlm_GetIconStatus (Nlm_GraphiC i, Nlm_Int2 item)
  772.  
  773. {
  774.   Nlm_IconData  extra;
  775.   Nlm_Boolean   status;
  776.  
  777.   status = 0;
  778.   if (i != NULL) {
  779.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  780.     status = extra.status;
  781.   }
  782.   return status;
  783. }
  784.  
  785. static void Nlm_SetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
  786.                               Nlm_CharPtr title, Nlm_Boolean savePort)
  787.  
  788. {
  789.   Nlm_IconData  extra;
  790.   Nlm_Handle    h;
  791.   Nlm_RecT      r;
  792.   Nlm_WindoW    tempPort;
  793.  
  794.   tempPort = Nlm_SavePortIfNeeded (i, savePort);
  795.   Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  796.   h = extra.title;
  797.   h = Nlm_SetString (h, title);
  798.   extra.title = h;
  799.   Nlm_SetPanelExtra ((Nlm_PaneL) i, &extra);
  800.   if (Nlm_GetVisible (i) && Nlm_GetAllParentsVisible (i)) {
  801.     Nlm_GetRect (i, &r);
  802.     Nlm_InvalRect (&r);
  803.   }
  804.   Nlm_RestorePort (tempPort);
  805. }
  806.  
  807. static void Nlm_GetIconTitle (Nlm_GraphiC i, Nlm_Int2 item,
  808.                               Nlm_CharPtr title, Nlm_sizeT maxsize)
  809.  
  810. {
  811.   Nlm_IconData  extra;
  812.   Nlm_Handle    h;
  813.  
  814.   if (title != NULL) {
  815.     Nlm_GetPanelExtra ((Nlm_PaneL) i, &extra);
  816.     h = extra.title;
  817.     Nlm_GetString (h, title, maxsize);
  818.   }
  819. }
  820.  
  821. static void Nlm_ResetIcon (Nlm_PaneL i)
  822.  
  823. {
  824.   Nlm_IconData  extra;
  825.  
  826.   Nlm_GetPanelExtra (i, &extra);
  827.   if (extra.title != NULL) {
  828.     extra.title = Nlm_HandFree (extra.title);
  829.   }
  830.   Nlm_SetPanelExtra (i, &extra);
  831. }
  832.  
  833. extern Nlm_IcoN Nlm_IconButton (Nlm_GrouP prnt, Nlm_Int2 pixwidth, Nlm_Int2 pixheight,
  834.                                 Nlm_IcnActnProc draw, Nlm_IcnChngProc inval,
  835.                                 Nlm_IcnClckProc click, Nlm_IcnClckProc drag,
  836.                                 Nlm_IcnClckProc hold, Nlm_IcnClckProc release)
  837.  
  838. {
  839.   Nlm_IcoN      ic;
  840.   Nlm_IconData  idata;
  841.  
  842.   ic = NULL;
  843.   if (prnt != NULL) {
  844.     Nlm_SelectFont (Nlm_systemFont);
  845.     ic = (Nlm_IcoN) Nlm_AutonomousPanel (prnt, pixwidth, pixheight,
  846.                                          (Nlm_PnlActnProc) draw, NULL, NULL,
  847.                                          sizeof (Nlm_IconData), Nlm_ResetIcon,
  848.                                          iconProcs);
  849.     if (ic != NULL) {
  850.       Nlm_SetPanelClick ((Nlm_PaneL) ic, (Nlm_PnlClckProc) click, (Nlm_PnlClckProc) drag,
  851.                          (Nlm_PnlClckProc) hold, (Nlm_PnlClckProc) release);
  852.       idata.inval = inval;
  853.       idata.value = 0;
  854.       idata.status = FALSE;
  855.       idata.title = NULL;
  856.       Nlm_SetPanelExtra ((Nlm_PaneL) ic, &idata);
  857.     }
  858.   }
  859.   return ic;
  860. }
  861.  
  862. extern void Nlm_FreeExtras (void)
  863.  
  864. {
  865.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  866. }
  867.  
  868. extern void Nlm_InitExtras (void)
  869.  
  870. {
  871.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 3);
  872.  
  873.   repeatProcs = &(gphprcsptr [0]);
  874.   repeatProcs->setTitle = Nlm_SetRepeatTitle;
  875.   repeatProcs->getTitle = Nlm_GetRepeatTitle;
  876.  
  877.   switchProcs = &(gphprcsptr [1]);
  878.   switchProcs->setValue = Nlm_SetSwitchValue;
  879.   switchProcs->getValue = Nlm_GetSwitchValue;
  880.  
  881.   iconProcs = &(gphprcsptr [2]);
  882.   iconProcs->setValue = Nlm_SetIconValue;
  883.   iconProcs->getValue = Nlm_GetIconValue;
  884.   iconProcs->setStatus = Nlm_SetIconStatus;
  885.   iconProcs->getStatus = Nlm_GetIconStatus;
  886.   iconProcs->setTitle = Nlm_SetIconTitle;
  887.   iconProcs->getTitle = Nlm_GetIconTitle;
  888. }
  889.